from enum import Enum


class ProtocolType(Enum):
    Rtu = "ModbusRtu"
    Tcp = "ModbusTcp"
    Udp = "ModbusUdp"
    RtuOverTcp = "ModbusRtuOverTcp"


class RegisterType(Enum):
    INPUT = 0
    OUTPUT = 1


def get_protocol_type_by_value(value: str) -> ProtocolType:
    """通过枚举值反推枚举类型"""
    for member in ProtocolType:
        if member.value == value:
            return member
    raise ValueError(f"'{value}' is not a valid ProtocolType")
